#ifndef TIMECONTROL_H
#define TIMECONTROL_H

#include <sys/time.h>
#include <time.h>

double second(){
	return clock()/(double)CLOCKS_PER_SEC;
}

class Timer{
	public:	
	typedef unsigned int uint;
	typedef double real;
	bool flag;

	uint c1, c2, cin, cin_tot, cout, cout_tot;
	real s1, s2, sin, sin_tot, sout, sout_tot;
	timeval tv;		
	
	Timer(){
		cin=cin_tot=cout=cout_tot=0; 
		sin=sin_tot=sout=sout_tot=0;
		flag=false;
	}
	
	void set(){
		gettimeofday(&tv, 0);
		s1= tv.tv_sec + tv.tv_usec/1000000.0;
		c1= clock();
		 	
		if (flag) {
			sout=s1-s2;
			sout_tot+=sout;
			cout=c1-c2;
			cout_tot+=cout;
		}
	}
	
	void get(){
		
		gettimeofday(&tv, 0);
		s2= tv.tv_sec + tv.tv_usec/1000000.0;
		
		sin=s2-s1;
		sin_tot+=sin;
	
		c2= clock();
		cin=c2-c1;
		cin_tot+=cin;
	
		flag=true;
	}
};



#endif